package com.jian.java;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;

import java.beans.Statement;
import java.util.Properties;

/**
 * @author Jiange
 * @create 2021-04-23-12:52
 */
//告诉拦截那个对象的哪个方法
@Intercepts(
        {
                @Signature(type = StatementHandler.class,method = "parameterize",args = java.sql.Statement.class)
        }
)
public class  MyPlugin implements Interceptor {
    //拦截目标对象的方法执行
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        //执行目标方法
        Object proceed = invocation.proceed();
        System.out.println("invocation"+invocation.getMethod());
        //返回执行后的返回值
        return proceed;
    }


    //包装目标对象  为目标对象创建一个代理对象
    @Override
    public Object plugin(Object o) {
        Object wrap = Plugin.wrap(o, this);
        System.out.println("plugin:"+o);
        //返回当前处理器对象的代理对象
        return wrap;
    }

    //将插件注册时的property设置进来
    @Override
    public void setProperties(Properties properties) {
        System.out.println(properties);
    }
}
